function Popup(width, height)
{
	this.width=(width==null?300:width);
	this.height=(height==null?200:height);

	this._displayElement = null
	this._foregroundElement = null
	this._backgroundElement = null
	
	this.showed = false;
}

Popup.prototype._createElements = function()
{
	if(this._backgroundElement == null)
	{
		this._backgroundElement = document.createElement("DIV");
		this._backgroundElement.className = "popup_background"
		this._backgroundElement.style.display="none"
		document.body.appendChild(this._backgroundElement)
	}
	if(this._foregroundElement == null)
	{
		this._foregroundElement = document.createElement("IFRAME");
		this._foregroundElement.className = "popup_foreground"
		this._foregroundElement.style.display="none"
		this._foregroundElement.style.width=this.width+"px"
		this._foregroundElement.style.height=this.height+"px"
		document.body.appendChild(this._foregroundElement)
	}
	if(this._displayElement == null)
	{
		this._displayElement = document.createElement("DIV");
		this._displayElement.className = "popup_display"
		this._displayElement.style.display="none"
		this._displayElement.style.width=this.width+"px"
		this._displayElement.style.height=this.height+"px"
		document.body.appendChild(this._displayElement)
	}
}

Popup.prototype._centerElements = function()
{
	this._foregroundElement.style.marginLeft = '-'+(this.width/2)+'px'
	this._foregroundElement.style.marginTop = '-'+(this.height/2)+'px'
	this._displayElement.style.marginLeft = this._foregroundElement.style.marginLeft
	this._displayElement.style.marginTop = this._foregroundElement.style.marginTop
}
Popup.prototype._displayElements = function()
{
	this._backgroundElement.style.display = "block"
	this._displayElement.style.display = "block"
	this._foregroundElement.style.display = "block"
}

Popup.prototype.showSmall = function(class_names, title, form_post, button_ok_function, button_cancel_function, modal, page, callBack)
{
	if(modal)
	{
		this.showModal('<div loading></div>')
	}
	else
	{
		this.show('<div loading></div>')
	}
	var postDatas = new Array()
	postDatas['class_names'] = class_names;
	postDatas['title'] = title;
	postDatas['form_post'] = form_post;
	postDatas['page'] = page;
	postDatas['button_ok_function'] = button_ok_function;
	postDatas['button_cancel_function'] = button_cancel_function;
	
	var this_object = this
	ajax.sendAsync("./action/smallPopup.php5?u="+new Date().getTime(), function(datas)
	{
		eval(datas)
		this_object.display(datas)
		datas = null
		if(callBack!=null)
		{
			callBack()
		}
	}, postDatas)
	
}

Popup.prototype.show = function(display)
{
	this.showModal(display)

	var thisObject = this
	this._backgroundElement.onclick = function()
	{
		thisObject.hide()
	}
}

Popup.prototype.showModal = function(display)
{
	this.showed = true;

	this._createElements();
	this._centerElements();
	this._displayElements();
	this.display(display)
	if(typeof(focusInput) == 'function')
	focusInput(this._displayElement)
}
Popup.prototype.display = function(display)
{
	if(display==null)
	{
		this._displayElement.innerHTML = '<div loading></div>'
	}
	else
	{
		switch(typeof(display))
		{
			case "string":
				var pos_start = display.indexOf("<script>");
				while(pos_start>=0)
				{
					var pos_end = display.indexOf("</script>", pos_start);
					if(pos_end>0)
					{
						var script = display.substr(pos_start+8, pos_end-pos_start-8)
						eval(script)
						pos_start = display.indexOf("<script>", pos_end);
					}
					else
					{
						pos_start = display.indexOf("<script>", pos_start+8);
					}
				}
				setHtml(this._displayElement, display)
				break;
			case "number":
				this._displayElement.innerHTML = display
				break;
			case "object":
				this._displayElement.appendChild(display);
				break;
			case "undefined":
				break;
			default:
				alert("Impossible d'afficher ce type d'élément : "+typeof(display))
				break;
		}
	}
}

Popup.prototype.hide = function()
{
	this.showed = false;

	document.body.removeChild(this._foregroundElement)
	document.body.removeChild(this._displayElement)
	document.body.removeChild(this._backgroundElement)

	this._foregroundElement = null;
	this._displayElement = null;
	this._backgroundElement = null;
}